<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>async修饰函数</h1>
		<script>
			// async修饰的函数，函数执行返回的是一个promise对象
			// 通常配合await等待关键字,await只能出现在async装饰的函数里面
			// await会等待 promise的resolve的结果
			function say(msg, delay) {
				return new Promise((resolve, reject) => {
					setTimeout(() => resolve(msg), delay);
				})
			}

			async function doit() {
				var m1 = await say("你好，我能加你个微信吗?", 4000);
				console.log(m1);
				var m2 = await say("走吃个串串", 3000);
				console.log(m2);
				return "国庆快乐！";
			}
			doit()
				.then(res => console.log(res))
			// var result = doit();
			// console.log(result);
		</script>
	</body>
</html>
